package cn.cloud.all.security.crypto.keygen;

import java.security.SecureRandom;

final class SecureRandomBytesKeyGenerator implements BytesKeyGenerator {

	private final SecureRandom random;

	private final int keyLength;

	SecureRandomBytesKeyGenerator() {
		this(8);
	}

	SecureRandomBytesKeyGenerator(int keyLength) {
		this.random = new SecureRandom();
		this.keyLength = keyLength;
	}

	public int getKeyLength() {
		return keyLength;
	}

	public byte[] generateKey() {
		byte[] bytes = new byte[keyLength];
		random.nextBytes(bytes);
		return bytes;
	}
}
